﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace test1
{
    /// <summary>
    /// 文件监控，触发事件
    /// </summary>
    public partial class fileAction : Form
    {
        public fileAction()
        {
            FileSystemWatcher p = new FileSystemWatcher(@"d:\ftp");
            p.EnableRaisingEvents = true;
            p.IncludeSubdirectories = true;
            p.Changed += new FileSystemEventHandler(p_Changed);
            p.Created += new FileSystemEventHandler(p_Created);
            p.Deleted += new FileSystemEventHandler(p_Deleted);   
        }
        private void p_Changed(object sender, FileSystemEventArgs e)
        {
            string s = e.Name;

            MessageBox.Show(s + "文件被更改于　" + DateTime.Now);
        }

        private void p_Created(object sender, FileSystemEventArgs e)
        {
            string s = e.Name;

            MessageBox.Show(s + "文件被创建于　" + DateTime.Now);
        }

        private void p_Deleted(object sender, FileSystemEventArgs e)
        {
            string s = e.Name;

            MessageBox.Show(s + "文件被删除于　" + DateTime.Now);
        }
    }
}
